package com.ruoyi.resturant.service.Impl;

import com.ruoyi.common.exception.BizException;
import com.ruoyi.resturant.domain.ResDish;
import com.ruoyi.resturant.domain.ResDish;
import com.ruoyi.resturant.domain.ResDish;
import com.ruoyi.resturant.mapper.ResDishMapper;
import com.ruoyi.resturant.mapper.ResDishMapper;
import com.ruoyi.resturant.mapper.ResDishMapper;
import com.ruoyi.resturant.service.IResDishService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResDishServiceImpl implements IResDishService {
    private static final Logger log = LoggerFactory.getLogger(ResDishServiceImpl.class);
    @Autowired
    private ResDishMapper resDishMapper;
    @Override
    public ResDish selectResDishById(Long id){
        return resDishMapper.selectResDishById(id);
    }
    @Override
    public List<ResDish> selectResDishByParam(String dishName){
        List<ResDish> resDishLst = resDishMapper.selectResDishByParam(dishName);
        return resDishLst;
    }
    @Override
    public int insertResDish(ResDish resDish){

        return resDishMapper.insertResDish(resDish);
    }
    @Override
    public int updateResDish(ResDish resDish){
        return resDishMapper.updateResDish(resDish);
    }
    @Override
    public int deleteResDishById(Long id){
        ResDish resDish = resDishMapper.selectResDishById(id);
        if(resDish == null) {
            throw new BizException(404, "该菜品ID" + id + "不存在");
        }
        log.info("该菜品ID" + id + "存在");
        return resDishMapper.deleteResDishById(id);
    }
}
